home *** CD-ROM | disk | FTP | other *** search
- /* RANDBRD.C --- p. 652 */
- #include <stdio.h>
- #include <dos.h>
- #define FCB_OPEN 0x0f
- main()
- {
- char input[80], buffer[256], far *old_dta;
- int option; /* Option for parsfnm */
- struct fcb fcb; /* File Control Block, FCB */
- int i, result;
- printf("Enter name of file from which we will "
- "read tow 128-byle records:\n(only drive and file "
- "name allowed, for example, A:MYFILE.DAT):");
- gets(input);
- /* parse file name using 'parsfnm' and an FCB */
- option = 1; /* means skip leading separators */
- parsfnm(input, &fcb, option);
- printf("Reading from \nDrive number: %d\n File name: %s\n",
- fcb.fcb_drive, fcb.fcb_name);
- /* Now open the file using DOS function 0fh (this
- * is not the same as "_open" which uses handles */
- if(bdosptr(FCB_OPEN, &fcb, 0) == -1)
- {
- printf("File open error\n");
- exit(1);
- }
- /* Save current disk transfer address and set up a
- * new one with enough room for data being read. */
- old_dta = getdta();
- setdta(buffer);
- /* Now set up the record size and start block */
- fcb.fcb_recsize = 128;
- fcb.fcb_random = 0L; /* start at record 0 */
- result = randbrd(&fcb, 2);
- printf("result = %d\n", result);
- if(result == 0) printf("Read ok\n");
- if(result == 1 || result == 3)
- printf("File ended during read\n");
- /* Print data read (assume ASCII text data) */
- printf("The first 26 characters are:\n");
- for(i = 0; i < 256; i++)
- putchar(buffer[i]);
- /* Reset DTA to old value */
- setdta(old_dta);
- }